﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO_HealthInsurance;

namespace DAO_HealthInsurance
{
    public  class DAOHospital:ConnectDatabase
    {
        public SqlCommand Cmd;
        public DTOHospitalInfo objHos;
        public DataTable ListHospital()
        {
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("ListHospital", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("HospitalInfo");
                da.Fill(dt);
                CloseConnect();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public int InsertHospital(DTOHospitalInfo objHos)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("InsertHospital", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@HospitalName", SqlDbType.VarChar, 50).Value = objHos.HospitalName;
                Cmd.Parameters.Add("@PhoneNO", SqlDbType.VarChar, 50).Value = objHos.HospitalPhone;
                Cmd.Parameters.Add("@Location", SqlDbType.VarChar,50).Value = objHos.HospitalLocation;
                Cmd.Parameters.Add("@Url", SqlDbType.VarChar,50).Value = objHos.HospitalUrl;

                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;
        }

        public int DeleteHospital(DTOHospitalInfo objHos)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("DeleteHospital", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@HospitalId", SqlDbType.Int).Value = objHos.HospitalId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }
        public int UpdateHospitalInfo(DTOHospitalInfo objHos)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("UpdateHospitalInfo", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@HospitalId", SqlDbType.Int).Value = objHos.HospitalId;
                Cmd.Parameters.Add("@HospitalName", SqlDbType.VarChar, 50).Value = objHos.HospitalName;
                Cmd.Parameters.Add("@PhoneNO", SqlDbType.VarChar, 50).Value = objHos.HospitalPhone;
                Cmd.Parameters.Add("@Location", SqlDbType.VarChar,50).Value = objHos.HospitalLocation;
                Cmd.Parameters.Add("@Url", SqlDbType.VarChar,50).Value = objHos.HospitalUrl;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }

        public DataTable GetHospitalById(DTOHospitalInfo objHos)
        {
            try
            {
                Cmd = new SqlCommand("GetHospitalById", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@HospitalId", SqlDbType.Int).Value = objHos.HospitalId;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("HospitalInfo");
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
